﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>
	    选择节点转向
    </title>
   <script language="JavaScript" src="../Comm/JScript.js" type="text/javascript" ></script>
   <script type="text/javascript" src="../Scripts/bootstrap/js/jquery.min.js"></script>
   <script type="text/javascript" src="../Scripts/QueryString.js" ></script>
   <link href="../Scripts/bootstrap/css/bootstrap.css" rel="Stylesheet" />

    <script type="text/javascript" src="../Scripts/bootstrap/js/bootstrap.min.js"></script>

    <!-- 引用通用的js文件. -->
    <script type="text/javascript" src="../Scripts/config.js"></script>
    <script type="text/javascript" src="../Comm/Gener.js"></script>
    <link rel="Stylesheet" href="../../DataUser/Style/ccbpm.css"  />
    <style type="text/css">
        label
        {
            display: inline-block;
            max-width: 100%;
            margin-bottom:0px;
            font-weight: normal; 
        }
    </style>
    <script type="text/javascript">
        var WorkID;
        var FK_Flow;
        var FK_Node;
        var FID;
        //初始化数据
        $(function () {
            WorkID = GetQueryString("WorkID");
            FK_Flow = GetQueryString("FK_Flow");
            FK_Node = GetQueryString("FK_Node");
            FID = GetQueryString("FID");

            var handler = new HttpHandler("BP.WF.HttpHandler.WF_WorkOpt");
            handler.AddUrlData();
            var data = handler.DoMethodReturnString("ToNodes_Init");
            if (data.indexOf("err@") != -1) {
                alert(data);
                return;
            }

            data = JSON.parse(data);
            var nodes = data.Nodes;
            var selectNodeID = data.SelectNode[0].NodeID;

            var html = "";
            var isSubYBD = false; //异表单

            for (var i = 0; i < nodes.length; i++) {
                var checked = "";
                //判断节点是否为异表单
                var node = nodes[i];
                if (node.NodeID == 0) {
                    if (node.NodeID == selectNodeID)
                        checked = "checked=checked";
                    html += "<span><input type='radio' id='RB_UnSameSheet' name='nodeSelect' value='RB_UnSameSheet' " + checked + " onclick='RBUnSameSheet(this);'>";
                    html += "<label for='RB_UnSameSheet'><b>可以分发启动的异表单节点</b></label></span>";
                    html += "<br/>";
                    isSubYBD = true;
                    continue;
                }

                //已有人员直接显示到人员选择器a标签上 
                var emps = new Entities("BP.WF.Template.SelectAccpers");
                emps.Retrieve("FK_Node", node.NodeID, "WorkID", WorkID);
                var addSpan = "";
                if (emps != null && emps.length > 0) {
                    for (var k = 0; k < emps.length; k++) {
                        if (k == 4) {
                            addSpan += emps[k].EmpName + "...";
                            break;
                        }
                        else {
                            if (k == emps.length - 1) {
                                addSpan += emps[k].EmpName;
                            }
                            else {
                                addSpan += emps[k].EmpName + ",";
                            }
                        }
                    }
                    addSpan = "<span style='color:black;'>(" + addSpan + ")</span>";
                }

                //异表单选择可以同时发送给多个节点
                if (isSubYBD == true) {
                    if (node.NodeID == selectNodeID)
                        checked = "checked=checked";
                    html += "<input type='checkbox' id='CB_" + node.NodeID + "' name='nodeSelect' " + checked + ">";
                    html += "<label for='CB_" + node.NodeID + "'>" + node.Name + "</label>";
                    //上一步发送人选择或者是根据工程类项目由发送人选择
                    if (node.DeliveryWay == 4 || node.DeliveryWay == 21) {
                        html += "- <a id=\"acc_link_" + node.NodeID + "\" target='_blank' href='javaScript:void(0)' onclick='SelectEmps(\"" + node.NodeID + "\")'>选择接受人员" + addSpan + "</a>";
                    }
                    html += "<br/>";
                } else {
                    if (node.NodeID == selectNodeID)
                        checked = "checked=checked";
                    html += "<input type='radio' id='RB_" + node.NodeID + "' name='nodeSelect' value='RB_" + node.NodeID + "' " + checked + "  onclick='SetUnEable(this);'>";
                    html += "<label for='RB_" + node.NodeID + "'>" + node.Name + "</label>";
                    //上一步发送人选择或者是根据工程类项目由发送人选择
                    if (node.DeliveryWay == 4 || node.DeliveryWay == 21) {
                        html += "- <a id=\"acc_link_" + node.NodeID + "\" target='_blank'  href='javaScript:void(0)' onclick='SelectEmps(\"" + node.NodeID + "\")'>选择接受人员" + addSpan + "</a>";
                    }
                    html += "<br/>";
                }

            }
            var tr = $("<tr><td>" + html + "</td></tr>");
            $("#TableNode").append(tr);


            $('#btnMsgModalOK').bind('click', function () {
                window.close();
            });

        });
       
        function SetUnEable(ctrl) {
            SetEnable(true);
        }

        function RBUnSameSheet(ctrl) {
            if (ctrl.checked) {
                SetEnable(false);
            }
            else {
                SetEnable(true);
            }
        }

        function SetEnable(enable) {
            var arrObj = document.all;
            for (var i = 0; i < arrObj.length; i++) {
                if (typeof arrObj[i].type != "undefined" && arrObj[i].type == 'checkbox') {
                    arrObj[i].disabled = enable;
                }
            }
        }
        function SetRBSameSheetCheck() {
            var arrObj = document.all;
            for (var i = 0; i < arrObj.length; i++) {
                if (typeof arrObj[i].type != "undefined" && arrObj[i].id.valueOf('RB_SameSheet') != -1) {
                    arrObj[i].checked = true;
                    break;
                }
            }
          
        }

        function returnWorkWindowClose(data) {
            location.href = location.href;
        }


        //选择接受人

        function SelectEmps(toNodeID) {
            $('#modalHeader').text("发送到节点");
            modalIframeSrc = "./Accepter.htm?FK_Node=" + FK_Node + "&FID=" + FID + "&WorkID=" + WorkID + "&FK_Flow=" + FK_Flow + "&ToNode=" + toNodeID +"&IsSend=0"+ "&s=" + Math.random();
            $('#iframeReturnWorkForm').attr('src', modalIframeSrc);
            $('#returnWorkModal').modal().show(); 
            
        }



        //选择节点发送
        function Send() {
            //获取选择的节点
            //获取同表单或者这个普通节点的选择的值
            var nodeID = $('input:radio:checked').val();
            var toNode = ""; // 跳转的节点
            if (nodeID == null || nodeID == ""){
                alert("您没有选择到达的节点");
                return;
            }
            //获取选择的异表单
            if (nodeID == "RB_UnSameSheet") {
                $.each($('input:checkbox'), function () {
                    if (this.checked)
                        toNode += this.id.replace("CB_","") + ",";
                });
            } else
                toNode = nodeID.replace("RB_", "");
            if (toNode == "") {
                alert("您没有选择到达的节点");
                return;
            }

            //执行发送
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_WorkOpt");
            handler.AddUrlData();
            handler.AddPara("ToNodes", toNode);
            var data = handler.DoMethodReturnString("ToNodes_Send");
            if (data.indexOf('err@') == 0) { //发送时发生错误
                alert(data);
                return;
            }

            if (data.indexOf('TurnUrl@') == 0) {  //发送成功时转到指定的URL 
                var url = data;
                url = url.replace('TurnUrl@', '');
                window.location.href = url;
                return;
            }


            if (data.indexOf('url@') == 0) {  //发送成功时转到指定的URL 

                if (data.indexOf('Accepter') != 0 && data.indexOf('AccepterGener') == -1) {

                    //求出来 url里面的FK_Node=xxxx 
                    var params = data.split("&");

                    for (var i = 0; i < params.length; i++) {
                        if (params[i].indexOf("ToNode") == -1)
                            continue;

                        toNodeID = params[i].split("=")[1];
                        break;
                    }
                    $('#modalHeader').text("发送到节点");
                    modalIframeSrc = "./Accepter.htm?FK_Node=" + FK_Node + "&FID=" + FID + "&WorkID=" + WorkID + "&FK_Flow=" + FK_Flow + "&ToNode=" + toNode + "&IsSend=0" + "&s=" + Math.random();
                    $('#iframeReturnWorkForm').attr('src', modalIframeSrc);
                    $('#returnWorkModal').modal().show();
                    return;
                }

                var url = data;
                url = url.replace('url@', '');
                window.location.href = url;
                return;
            }
            OptSuc(data);

        }

        //发送 退回 移交等执行成功后转到  指定页面
        function OptSuc(msg) {

            if ($('#returnWorkModal:hidden').length == 0 && $('#returnWorkModal').length > 0) {
                $('#returnWorkModal').modal().hide()
            }
            msg = msg.replace("@查看<img src='/WF/Img/Btn/PrintWorkRpt.gif' >", '')

            $("#msgModalContent").html(msg.replace(/@/g, '<br/>'));
            var trackA = $('#msgModalContent a:contains("工作轨迹")');
            var trackImg = $('#msgModalContent img[src*="PrintWorkRpt.gif"]');
            trackA.remove();
            trackImg.remove();

            $("#msgModal").modal().show();
           
        }


        //取消或者返回
        function Cancel() {
            var url = "../MyFlow.htm?FK_Flow=" + FK_Flow + "&FK_Node=" + FK_Node + "&WorkID=" + WorkID + "&FID=" + FID;
            window.location.href = url;
        }
    </script>

    <base target="_self" /> 
</head>
<body>
    <div style="text-align: center; position: absolute; background-color: white; height: 100%;left: 15%; right: 15%">
        <table width="100%" align="center"  id="TableNode">
            <caption>您好:<img src='/DataUser/UserIcon/adminSmaller.png' border=0  style='height:15px;width:15px;padding-right:5px;vertical-align:middle;'  onerror="src='/DataUser/UserIcon/DefaultSmaller.png'" />admin   --   请选择到达的节点</caption>
        </table>
        <input type=button id="Btn_Send" onclick="Send();"value="发送"/>
        <input type=button id="Btn_Cancel" onclick="Cancel();" value="取消/返回"/>
    </div>


    <!--杨玉慧加   提示信息弹出窗口-->
    <div class="modal fade" id="msgModal" data-backdrop="static">
        <div class="modal-dialog" >
            <div class="modal-content" style="border-radius: 0px;">
                <div class="modal-header">
                    <button type="button" class="close" id="btnMsgModalOK1" aria-hidden="true" style="color: white;
                        opacity: 1; display: none;">
                        ×</button>
                    <h4 class="modal-title">
                        提示信息</h4>
                </div>
                <div class="modal-body" style="text-align: left; word-wrap: break-word;">
                    <div style="width:100%; border: 0px; height: 200px;" id="msgModalContent" name="iframePopModalForm">
                    </div>
                    <div style="text-align: right;">
                        <button type="button" id="btnMsgModalOK" class="btn" data-dismiss="modal">
                            确定</button>
                    </div>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>
    <!-- /.modal -->

    <div class="modal fade" id="returnWorkModal" data-backdrop="static">
      <div class="modal-dialog">
           <div class="modal-content" style="border-radius:0px;width:900px;text-align:left;">
              <div class="modal-header">
                  <button type="button" style="color:white;float: right;background: transparent;border: none;" data-dismiss="modal" aria-hidden="true">&times;</button>
                   <h4 class="modal-title" id="modalHeader">工作退回</h4>
               </div>
               <div class="modal-body" style="margin:0px;padding:0px">
                   <iframe style="width:100%;border:0px;height:450px;" id="iframeReturnWorkForm" name="iframeReturnWorkForm"></iframe>
               </div>
           </div><!-- /.modal-content -->'
       </div><!-- /.modal-dialog -->'
   </div>

</body>
</html>
